<template>
	<view class="container">
		<view class="top">
			<u-navbar placeholder :autoBack="false"  bgColor="transparent" safeAreaInsetTop>
				<view class="app-name" slot="left">
					DailyEnglish
					<u-avatar class="avatar" @click="toUser" :text="hasLogin?'':'未登录'" :src="userInfo.avatar" fontSize="10"
						randomBgColor></u-avatar>
				</view>
			</u-navbar>
			<view class="date">
				学英语 · 品生活 · 阅人生
			</view>
			<view class="tab">
				<u-tabs lineWidth="20" sticky lineHeight="3" lineColor="#B275F2" :sticky="true" :list="tabs"
					 :current="tabIndex" @change="tabChange" :activeStyle="activeStyle"
					:inactiveStyle="inActiveStyle" :duration="0.5" />
			</view>
		</view>
		<view class="list">
			<!-- 列表 -->
			<swiper :current="tabIndex" :style="{height:getHeight}" @change="swiperChange">
				<swiper-item v-for="(tab,i) in tabs" :key="i">
					<mescroll-item :height="getHeight" :i="i" :index="tabIndex" :tabs="tabs"></mescroll-item>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	import {
		mapGetters,
	} from 'vuex';
	// tab栏数据
	const tabs = [{
			name: `每日一句`,
			value: 'daily-english',
			api: 'daily-english'
		}, {
			name: `英语美文`,
			value: 'opendb-news-articles',
			api: 'opendb-news-articles'
		},
		// {
		// 	name: `每日盲盒`,
		// 	value: 'checked',
		// 	api: '/api/company/job/checked'
		// },

	]
	import MescrollItem from "./components/mescroll-swiper-item.vue";
	export default {
		components: {
			MescrollItem
		},

		data() {
			return {
				list: [],
				// tab栏数据
				tabs,
				// 当前标签索引
				tabIndex: 0,
				// tab 激活的样式
				activeStyle: {
					color: '#B275F2',
					fontWeight: 'bold',
					fontSize: '28rpx'
				},
				// tab 未激活的样式
				inActiveStyle: {
					color: '#606266',
					fontSize: '28rpx'
				},
			}
		},
		computed: {
			...mapGetters({
				userInfo: 'user/info',
				hasLogin: 'user/hasLogin'
			})
		},
		onReady() {
			// 防止无法获取tab
			setTimeout(()=>{
				this.initNavHeight()
			},500)
		},
		methods: {
			// tab切换
			tabChange(e) {
				this.tabIndex = e.index
			},
			// 轮播菜单
			swiperChange(e) {
				this.tabIndex = e.detail.current
			},
			/**
			 * 去登陆
			 */
			toUser() {
				uni.navigateTo({
					url: '/pages/ucenter/ucenter'
				})
			}
		},
	}
</script>

<style scoped lang="scss">
	.container {
		background-image: url(https://vkceyugu.cdn.bspapp.com/VKCEYUGU-366ba130-3d1f-4284-a453-7dde238bdc9d/373adc5c-1e20-495c-94ec-e6a5cfed2209.png);
		// background-position: center top;
		background-size: 100% auto;
		background-repeat: no-repeat;
		display: flex;
		flex-direction: column;
		background-color: white;
		background-image: linear-gradient(-225deg, #E3FDF5 0%, #FFE6FA 100%);

		.avatar {
			border-radius: 50%;
			margin-left:20rpx;
			box-shadow: 0 0 0 2px rgba(45, 140, 240, .2);
		}
		.list{
			padding:0 30rpx;
		}

		.app-name {
			// margin-top: 100rpx;
			color: $main;
			font-size: 50rpx;
			font-weight: bold;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
			// margin-right: 30vw;
		}

		.date {
			font-size: 28rpx;
			margin-top: 10rpx;
			color: $main;
			margin-left:30rpx;
		}

		.tab {
			// margin: 20rpx 0;
			display: flex;
			flex-direction: row;
			justify-content: flex-start;
		}
	}
</style>
